package com.bz.xtcx.manager.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bz.xtcx.manager.entity.CmsFile;
import com.bz.xtcx.manager.mapper.CmsFileMapper;
import com.bz.xtcx.manager.service.ICmsFileService;
import com.bz.xtcx.manager.utils.MyFileUtil;

@Service
public class CmsFileService implements ICmsFileService {
	
	private final Logger logger = LoggerFactory.getLogger(CmsFileService.class);
	
	@Autowired
	private CmsFileMapper cmsFileMapper;

	@Override
	public boolean add(CmsFile e) {
		int result = cmsFileMapper.insert(e);
		if(result > 0) {
			return true;
		}
		return false;
	}

	@Override
	public boolean del(String id) {
		CmsFile file = cmsFileMapper.findById(id);
		if(file != null) {
			MyFileUtil util = new MyFileUtil();
			boolean flag = util.delFile(file.getSavePath());//删除文件
			if(!flag) {
				logger.debug("删除文件失败：" + file.getSavePath());
			}
			if(cmsFileMapper.del(id) > 0) {//删除数据
				return true;
			}
		}
		return false;
	}

}
